package com.dragon.common.modules.file.common.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @author Chris Chan
 * Create On 2025/8/29 下午7:06
 * Use for: 文件策略 条件
 * Explain:
 */
public class FileStrategyCondition implements Condition {
    
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(
            ConditionalOnFileStrategy.class.getName());
        if (attributes != null) {
            String requiredStrategy = (String) attributes.get("value");
            String activeStrategy = context.getEnvironment()
                .getProperty("file.strategy", "local");
            return requiredStrategy.equals(activeStrategy);
        }
        return false;
    }
}